import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/widgets/buttons/debouncedMaterialButton.dart';
import 'package:intl/intl.dart';

import '../../themes/appTheme.dart';

class ShowStudentNewAssessmentDialog extends StatefulWidget {
  ShowStudentNewAssessmentDialog({
    Key? key,
  }) : super(key: key);

  _ShowStudentNewAssessmentDialogState createState() =>
      new _ShowStudentNewAssessmentDialogState();
}

class _ShowStudentNewAssessmentDialogState
    extends State<ShowStudentNewAssessmentDialog> {
  var box = Hive.box('appconfig');

  @override
  Widget build(BuildContext context) {
    String notshowtoday = box.get('notshowtoday', defaultValue: '').toString();
    bool notshow =
        notshowtoday == DateFormat('yyyyMMdd').format(DateTime.now());

    return AlertDialog(
      title: Text('You received a new assessment'.tr),
      titleTextStyle: TextStyle(
          fontFamily: 'Montserrat',
          letterSpacing: 1,
          color: Get.isDarkMode
              ? Get.theme.primaryColorDark
              : Get.theme.primaryColorLight,
          fontSize: 20),
      backgroundColor: Get.theme.primaryColor,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(12),
        ),
      ),
      content: Container(
        width: 350,
        height: 208,
        child: Column(children: [
          Text(
            'It will take around 20 minutes, do you want to start now?'.tr,
            style: TextStyle(
              fontSize: 16.0,
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight,
            ),
          ),
          Expanded(
            flex: 2,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                MaterialButton(
                  //padding: EdgeInsets.symmetric(vertical: 12.0,horizontal: 60.0),
                  color: Get.isDarkMode
                      ? AppTheme.colors.darkTheme2
                      : Get.theme.primaryColorLight,
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  child: Text(
                    'Cancel'.tr,
                    style: TextStyle(color: Get.theme.primaryColorDark),
                  ),
                ),
                DebouncedMaterialButton(
                  color: Get.theme.primaryColorDark,
                  onPressed: () {
                    Get.offAllNamed('/student/assessments');
                  },
                  child: Text(
                    'Continue'.tr,
                    style: TextStyle(
                        color: Get.isDarkMode
                            ? Colors.black
                            : Get.theme.primaryColorLight),
                  ),
                ),
              ],
            ),
          ),
          Expanded(
            child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Checkbox(
                  value: notshow,
                  onChanged: (value) {
                    setState(() {
                      notshow = value as bool;
                      if (notshow) {
                        box.put('notshowtoday',
                            DateFormat('yyyyMMdd').format(DateTime.now()));
                      } else {
                        box.put('notshowtoday', '');
                      }
                    });
                  }),
              Text("Don't show today".tr,
                  style: TextStyle(
                      fontSize: 14.0,
                      color: Get.isDarkMode
                          ? Get.theme.primaryColorDark
                          : Get.theme.primaryColorLight)),
            ]),
          ),
        ]),
      ),
    );
  }
}
